#include "ssd1306.h"
#include "main.h"
#include "cmsis_os.h"

//ADDR(0x78)+WriteCom(0)/WriteData(0x40)+Data
//InitData: 0xae, 0x20, 0x10, 0xb0, 0xc8, 0x00, 0x10, 0x40, 0x81, 0/*light*/, 0xa1, 0xa6, 0xa8, 0x3f, 0xa4, 0xd3, 0x00, 0xd5, 0xf0, 0xd9, 0x22, 0xda, 0x12, 0xdb, 0x20, 0x8d, 0x14, 0xaf
//Write one byte pixel: ADDR+WriteCom+3 byte coordinate data，ADDR+WriteData+pixel byte
//coordinate: 0xb0+7-(Y/8), X&0x0f, 0x10+(X>>4)

void ssd1306::init(I2C_HandleTypeDef *hi2c)
{
  hi2c_ = hi2c;
  osDelay(500);
  HAL_I2C_Mem_Write(hi2c, ssd1306_addr_, write_comment_, I2C_MEMADD_SIZE_8BIT, init_, 28, 1000);
}

void ssd1306::display(uint8_t *data)
{
  HAL_I2C_Mem_Write(hi2c_, ssd1306_addr_, write_comment_, I2C_MEMADD_SIZE_8BIT, origin_, 3, 1000);
  HAL_I2C_Mem_Write(hi2c_, ssd1306_addr_, write_data_, I2C_MEMADD_SIZE_8BIT, data, 1024, 1000);
}